package com.lizhao.win007com.info.webapi.controller;

import com.lizhao.win007com.commons.pojo.info.model.*;
import com.lizhao.win007com.commons.restful.JsonResult;
import com.lizhao.win007com.info.service.IInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "info")
@RequestMapping("/info")
public class InfoController {
    @Autowired
    private IInfoService infoService;

    /****************************rateinfo*******************************/
    //主流胜率数据
    @PostMapping("list/rate")
    @ApiOperation("获取胜率")
    public JsonResult<List<RateInfo>> loadRateInfo(@RequestBody Map<String,String> postData){
        Integer leagueid = Integer.valueOf(postData.get("leagueid"));
        String relation = postData.get("relation");
        List<RateInfo> list = infoService.getFullRateInfoByLeagueIdAndrelation(leagueid, relation);

        return JsonResult.ok("完成获取对阵数据", list);
    }

    /****************************companyinfo*******************************/
    //获取公司信息
    @GetMapping("/companyinfo/list")
    @ApiOperation("获取公司信息")
    public JsonResult<List<CompanyInfo>> listCompanyInfo(){
        List<CompanyInfo> list = infoService.getAllCompanyInfo();
        System.out.println("aaaaa");
        return JsonResult.ok("获取到公司信息",list);
    }

    /****************************leagueinfo*******************************/
    //获取联赛配置
    @GetMapping("/leagueinfo/list")
    @ApiOperation("获取联赛配置")
    public JsonResult<List<LeagueInfo>> listLeagueInfo(){
        List<LeagueInfo> list = infoService.getAllLeagueInfo();
        return JsonResult.ok("获取到联赛配置信息",list);
    }

    //获取开放的联赛赛事类型
    @GetMapping("/leagueinfo/openleaguelist")
    @ApiOperation("获取开放的赛事数据")
    public JsonResult<List<LeagueInfo>> listOpenLeagueInfo(){
        List<LeagueInfo> list = infoService.getOpenLeagueInfo();
        return JsonResult.ok("获取到开放的联赛赛事类型",list);
    }

    /****************************cupinfo*******************************/
    //获取杯赛配置
    @GetMapping("/cupinfo/list")
    @ApiOperation("获取杯赛配置")
    public JsonResult<List<CupInfo>> listCupInfo(){
        List<CupInfo> list = infoService.getAllCupInfo();
        return JsonResult.ok("获取到杯赛配置信息",list);
    }

    //获取开放的杯赛赛事类型
    @GetMapping("/leagueinfo/opencuplist")
    @ApiOperation("获取开放的赛事数据")
    public JsonResult<List<CupInfo>> listOpenCupInfo(){
        List<CupInfo> list = infoService.getOpenCupInfo();
        return JsonResult.ok("获取到开放的杯赛赛事类型",list);
    }

    /****************************typeinfo*******************************/
    //获取配置模块信息
    @GetMapping("/typeinfo/list")
    @ApiOperation("获取配置模块信息")
    public JsonResult<List<TypeInfo>> listTypeInfo(){
        List<TypeInfo> list = infoService.getAllTypeInfo();
        return JsonResult.ok("获取到配置模块信息",list);
    }

    /****************************configinfo*******************************/
    //获取配置python生成文件的信息
    @GetMapping("/configinfo/list")
    @ApiOperation("获取路径配置信息")
    public JsonResult<List<ConfigInfo>> listConfigInfo(){
        List<ConfigInfo> list = infoService.getConfigInfo();
        return JsonResult.ok("获取到路径配置信息",list);
    }

    //修改配置路径
    @PostMapping("/configinfo/update")
    @ApiOperation("修改路径配置")
    public JsonResult updateConfigInfo(@RequestBody Map<String,String> config){
        String path = config.get("path");
        Integer sleep = Integer.valueOf(config.get("sleep"));

        infoService.updateConfigInfo(path,sleep);
        return JsonResult.ok();
    }

    /****************************public*******************************/
    //修改入库信息
    @PostMapping("/update")
    @ApiOperation("修改switch状态")
    public JsonResult updateTypeInfo(@RequestBody Map<String,String> info){
        String type = info.get("type");
        Integer id = Integer.valueOf(info.get("id"));
        String field = info.get("field");
        String value = info.get("value");
        String table = null;

        switch (type){
            case "typeinfo":
                table = "typeinfo";
                break;
            case "companyinfo":
                table = "companyinfo";
                break;
            case "leagueinfo":
                table = "leagueinfo";
                break;
            case "cupinfo":
                table = "cupinfo";
                break;
            case "seasoninfo":
                table = "seasoninfo";
                break;

        }
        if (table != null) infoService.updateByTableAndIdAndValue(table,id,field,value);
        return JsonResult.ok();
    }

    //获取监控表全数据
    @GetMapping("/monitor/avg/all")
    public JsonResult<List<MonitorAvgInfo>> listMonitorInfo(){
        List<MonitorAvgInfo> list = infoService.getMonitorInfo();
        return JsonResult.ok("获取到监控表数据",list);
    }

    // 获取监控表平赔数据
    @GetMapping("/monitor/avg/easy")
    public JsonResult<List<MonitorEasyInfo>> listMonitorEasyInfo(){
        List<MonitorEasyInfo> list = infoService.getMonitorEasyInfo();
        return JsonResult.ok("获取到监控表数据",list);
    }
}
